// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   People.java

package com.sgame.android.social;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.sgame.android.MLog;
import com.sgame.android.Mobage;
import com.sgame.android.data.MBUParcelableUser;
import com.sgame.android.data.User;
import com.sgame.android.lang.ErrorMap;
import com.sgame.android.lang.SimpleAPIStatus;
import com.sgame.android.network.InvalidCredentialsConfigurationException;
import com.sgame.android.lang.Error;

public class People extends CommonAPIBase
{

    public static interface OnGetUsersComplete
    {

        public abstract void onSuccess(ArrayList arraylist, PagingResult pagingresult);

        public abstract void onError(Error error);
    }

    public static interface OnGetUserComplete
    {

        public abstract void onSuccess(User user);

        public abstract void onError(Error error);
    }


    public People()
    {
    }

    private static User.Field[] mapFields(User.Field currFields[])
    {
        int length = currFields.length;
        User.Field newFields[] = new User.Field[length];
        for(int i = 0; i < length; i++)
            newFields[i] = User.Field.valueOf(currFields[i].name());

        return newFields;
    }

    private static User convertUser(User currUser)
    {
        User returnUser = new User();
        returnUser.setId(currUser.getId());
        returnUser.setDisplayName(currUser.getDisplayName());
        returnUser.setNickname(currUser.getNickname());
        returnUser.setAboutMe(currUser.getAboutMe());
        returnUser.setAge(currUser.getAge());
        returnUser.setBirthday(currUser.getBirthday());
        returnUser.setHasApp(currUser.isHasApp());
        returnUser.setThumbnailUrl(currUser.getThumbnailUrl());
        returnUser.setAgeRestricted(false);
        returnUser.setIsVerified(true);
        return returnUser;
    }

    private static ArrayList convertMultipleUsers(List currUsers)
    {
        ArrayList results = new ArrayList();
        User userIter;
        for(Iterator i$ = currUsers.iterator(); i$.hasNext(); results.add(convertUser(userIter)))
            userIter = (User)i$.next();

        return results;
    }

    private static PagingOption mapOptions(PagingOption options)
    {
        return new PagingOption(options.start, options.count);
    }

    public static void getCurrentUser(final IMobageHttpResponseHandler.OnGetUserResponseHandler onComplete)
    {
    	Error error;
    	if (!isLogin()) {
    		error = new Error(ErrorMap.COMMON_APIINVALID_SESSION);
    		MLog.d("People", Mobage.a(Mobage.c("invalid_session")), error);
    		onComplete.onError(error);
    		return;
    	}
    	try {
    		SgameJsonHttpRequestExecute.getCurrentUser(Mobage.createSgameHttpClient(), Mobage.getUser(), Mobage.getInstance().getAppKey(), onComplete);
    		return;
    	}
    	catch (InvalidCredentialsConfigurationException ex)
    	{
    		error = new Error(ErrorMap.MOBAGE_NOT_INITIALIZED, ex);
    		MLog.d("People", Mobage.a(Mobage.c("invalid_session")), error);
    		onComplete.onError(error);
    	}
    }

    public static void getCurrentUser(final IGetCurrentUserCallback onComplete)
    {
    	if (Mobage.isLogin())
    	{
    		User localUser;
    		if ((localUser = Mobage.getSession().getUser()) == null)
    		{
    			getCurrentUser(new IMobageHttpResponseHandler.OnGetUserResponseHandler()
    			{
    				public final void onComplete(User user)
    				{
    					onComplete.onComplete(SimpleAPIStatus.success, null, user);
    				}

    				public final void onError(Error error)
    				{
    					onComplete.onComplete(SimpleAPIStatus.error, error, null);
    				}
    			});
    			return;
    		}

    		MBUParcelableUser.a(localUser.toJson());
    		onComplete.onComplete(SimpleAPIStatus.success, null, localUser);

    		return;
    	}
    	MLog.d("People:", "Not Logged in");
    	onComplete.onComplete(SimpleAPIStatus.error, null, null);
    }

    public static void getUser(String userId, final IMobageHttpResponseHandler.OnGetUserResponseHandler onComplete)
    {
    	ArrayList localArrayList;
		localArrayList = new ArrayList();
		localArrayList.add(userId);
		Error error;
		if (!isLogin())
		{
			error = new Error(ErrorMap.COMMON_APIINVALID_SESSION);
			MLog.d("People", Mobage.a(Mobage.c("invalid_session")), error);
			onComplete.onError(error);
			return;
		}
		getUsers(localArrayList, new IMobageHttpResponseHandler.OnGetUsersResponseHandler()
		{
			public final void onComplete(List<User> users, PageOptionsResult paramAnonymousPageOptionsResult) {
				if ((users != null) && (users.size() > 0)) {
					onComplete.onComplete((User)users.get(0));
					return;
				}
				onComplete.onComplete(null);
			}

			public final void onError(Error error)
			{
				onComplete.onError(error);
			}
		});
    }

    public static void getUser(String userId, final IGetUserCallback onComplete)
    {
    	getUser(userId, new IMobageHttpResponseHandler.OnGetUserResponseHandler()
    	{
    		public final void onComplete(User user) {
    			onComplete.onComplete(SimpleAPIStatus.success, null, user);
    		}

    		public final void onError(Error error)
    		{
    			onComplete.onComplete(SimpleAPIStatus.error, error, null);
    		}
    	});
    }

    public static void getUsers(List<String> userIds, IMobageHttpResponseHandler.OnGetUsersResponseHandler responseHandler)
    {
    	Error error;
    	if (!isLogin()) {
    		error = new Error(ErrorMap.COMMON_APIINVALID_SESSION);
    		MLog.d("People", Mobage.a(Mobage.c("invalid_session")), error);
    		responseHandler.onError(error);
    		return;
    	}
    	try {
    		SgameJsonHttpRequestExecute.getUsers(userIds, Mobage.createSgameHttpClient(), Mobage.getUser(), Mobage.getInstance().getAppKey(), responseHandler);
    		return;
    	}
    	catch (InvalidParameterException ex)
    	{
    		error = new Error(ErrorMap.COMMON_APIMETHOD_INVALID_ARGUMENT, ex);
    		MLog.d("People", Mobage.a(Mobage.c("missing_userid")), error);
    		responseHandler.onError(error);
    	}
    }

    public static void getUsers(List<String> userIds, final IGetUsersCallback onComplete)
    {
    	getUsers(userIds, new IMobageHttpResponseHandler.OnGetUsersResponseHandler()
    	{
    		public final void onComplete(List<User> userList, PageOptionsResult paramAnonymousPageOptionsResult)
    		{
    			onComplete.onComplete(SimpleAPIStatus.success, null, userList);
    		}

    		public final void onError(Error error)
    		{
    			onComplete.onComplete(SimpleAPIStatus.error, error, null);
    		}
    	});
    }

    public static void getFriends(String userId, PagingOption options, IMobageHttpResponseHandler.OnGetUsersResponseHandler responseHandler)
    {
    	Error error;
    	if (!isLogin()) {
    		error = new Error(ErrorMap.COMMON_APIINVALID_SESSION);
    		MLog.d("People", Mobage.a(Mobage.c("invalid_session")), error);
    		responseHandler.onError(error);
    		return;
    	}
    	try {
    		SgameJsonHttpRequestExecute.getFriends(userId, options, Mobage.createSgameHttpClient(), Mobage.getUser(), Mobage.getInstance().getAppKey(), responseHandler);
    		return;
    	}
    	catch (InvalidParameterException ex)
    	{
    		error = new Error(ErrorMap.COMMON_APIMETHOD_INVALID_ARGUMENT, ex);
    		MLog.d("People", Mobage.a(Mobage.c("missing_userid")), error);
    		responseHandler.onError(error);
    		return;
    	}
    	catch (InvalidCredentialsConfigurationException ex)
    	{
    		error = new Error(ErrorMap.MOBAGE_NOT_INITIALIZED, ex);
    		MLog.d("People", Mobage.a(Mobage.c("invalid_session")), error);
    		responseHandler.onError(error);
    	}
    }

    public static void getFriends(String userId, int pageSize, int start, final IGetFriendsCallback onComplete)
    {
    	getFriends(userId, new PagingOption(start, pageSize), new IMobageHttpResponseHandler.OnGetUsersResponseHandler()
    	{
    		public final void onComplete(List<User> list, PageOptionsResult pageOptionsResults)
    		{
    			onComplete.onComplete(SimpleAPIStatus.success, null, list, pageOptionsResults.getStart(), pageOptionsResults.getCount());
    		}

    		public final void onError(Error error)
    		{
    			onComplete.onComplete(SimpleAPIStatus.error, error, null, -1, -1);
    		}
    	});
    }

    public static void getFriends(User user, int pageSize, int start, IGetFriendsCallback onComplete)
    {
    	getFriends(user.getId(), pageSize, start, onComplete);
    }

    public static void getFriendsWithGame(String userId, PagingOption options, IMobageHttpResponseHandler.OnGetUsersResponseHandler responseHandler)
    {
    	Error error;
    	if (!isLogin()) {
    		responseHandler.onError(new Error(ErrorMap.COMMON_APIINVALID_SESSION));
    		return;
    	}
    	try
    	{
    		SgameJsonHttpRequestExecute.getFriendsWithGame(userId, options, Mobage.createSgameHttpClient(), Mobage.getUser(), Mobage.getInstance().getAppKey(), responseHandler);
    		return;
    	}
    	catch (InvalidParameterException ex)
    	{
    		error = new Error(ErrorMap.COMMON_APIMETHOD_INVALID_ARGUMENT, ex);
    		MLog.d("People", Mobage.a(Mobage.c("missing_userid")), error);
    		responseHandler.onError(error);
    	}
    }

    public static void getFriendsWithGame(String userId, int pageSize, int start, final IGetFriendsWithGameCallback onComplete)
    {
    	getFriendsWithGame(userId, new PagingOption(start, pageSize), new IMobageHttpResponseHandler.OnGetUsersResponseHandler()
    	{
    		public final void onComplete(List<User> list, PageOptionsResult pageOptionsResults)
    		{
    			onComplete.onComplete(SimpleAPIStatus.success, null, list, pageOptionsResults.getStart(), pageOptionsResults.getCount());
    		}

    		public final void onError(Error error)
    		{
    			onComplete.onComplete(SimpleAPIStatus.error, error, null, -1, -1);
    		}
    	});
    }

    public static void SendFriendInviteToEmail(String paramString, final ISendFriendInvite handler)
    {
    	try
    	{
    		SgameJsonHttpRequestExecute.sendFriendInviteToEmail(paramString, Mobage.createSgameHttpClient(), Mobage.getUser(), Mobage.getInstance().getAppKey(), new IMobageHttpResponseHandler.OnSendFriendInviteToEmailIfPossibleResponseHandler()
    		{
    			public final void onError(Error paramAnonymousError)
    			{
    				handler.onComplete(SimpleAPIStatus.error, new Error(ErrorMap.SERVER_ERROR, paramAnonymousError));
    			}

    			public final void onComplete()
    			{
    				handler.onComplete(SimpleAPIStatus.success, null);
    			}
    		} );
    		return;
    	}
    	catch (InvalidParameterException ex)
    	{
    		handler.onComplete(SimpleAPIStatus.error, new Error(ErrorMap.COMMON_APIMETHOD_INVALID_ARGUMENT, ex));
    		return;
    	}
    	catch (InvalidCredentialsConfigurationException ex)
    	{
    		handler.onComplete(SimpleAPIStatus.error, new Error(ErrorMap.MOBAGE_NOT_INITIALIZED, ex));
        }
    }

    public static abstract interface ISendFriendInvite
    {
    	public abstract void onComplete(SimpleAPIStatus paramSimpleAPIStatus, Error paramError);
    }

    public static abstract interface IGetFriendsWithGameCallback
    {
      public abstract void onComplete(SimpleAPIStatus paramSimpleAPIStatus, Error paramError, List<User> paramList, int paramInt1, int paramInt2);
    }

    public static abstract interface IGetFriendsCallback
    {
      public abstract void onComplete(SimpleAPIStatus paramSimpleAPIStatus, Error paramError, List<User> paramList, int paramInt1, int paramInt2);
    }

    public static abstract interface IGetUsersCallback
    {
      public abstract void onComplete(SimpleAPIStatus paramSimpleAPIStatus, Error paramError, List<User> paramList);
    }

    public static abstract interface IGetUserCallback
    {
      public abstract void onComplete(SimpleAPIStatus paramSimpleAPIStatus, Error paramError, User paramUser);
    }

    public static abstract interface IGetCurrentUserCallback
    {
      public abstract void onComplete(SimpleAPIStatus paramSimpleAPIStatus, Error paramError, User paramUser);
    }

}
